package com.tanhua.server.controller;

import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public void login(@RequestBody Map map) {
        String phone = String.valueOf(map.get("phone"));
        userService.sendMsg(phone);
    }
    //验证登录
    @PostMapping("/loginVerification")
    public ResponseEntity<Object> loginVerification(@RequestBody Map map) {
            //获取参数中的号码和验证码
            String phone = (String) map.get("phone");
            String code = (String) map.get("verificationCode");
            //调用servcie的方法进行登录校验
            Map resMap = userService.loginVerification(phone, code);
            return ResponseEntity.ok(resMap);
    }
}
